package com.qf.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.mapper.GoodsMapper;
import com.qf.pojo.Goods;
import com.qf.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    GoodsMapper goodsMapper;

    @Override
    public List<Goods> goodsList(Integer categoryId) {
        PageHelper.startPage(1,4 );


        List<Goods> goods = goodsMapper.goodsList(categoryId);

        return goods;
    }

    @Override
    public Goods detail(Integer id) {
        return goodsMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<Goods> listAll(Integer id,Integer pageNum, Integer pageSize,Integer state) {
        PageHelper.startPage(pageNum, pageSize);



        if (state==null){
            PageHelper.orderBy("create_time");

        }else {
            if (state==1){
                PageHelper.orderBy("price");
            }else {
                PageHelper.orderBy("create_time");
            }
        }

//        PageHelper.orderBy("create_time");

        List<Goods> goodsList = goodsMapper.selectById(id);


        PageInfo<Goods> pageInfo=new PageInfo<>(goodsList);
        return pageInfo;
    }


}
